package com.aoip.telemetry.telemetry.core.util;

/**
 * 进制转换工具类
 *
 * @author chenbai
 * @version 1.0
 * @date 2021/5/29 12:00
 */
public class BaseSystemUtil {


    /**
     * 进制转换并填充固定位数
     *
     * @param num            待转换字符串数字
     * @param bit            填充固定位数字符串
     * @param fromBaseSystem 源字符串进制格式
     * @param toBaseSystem   转换后字符串进制格式
     * @return java.lang.String
     * @author chenbai
     * @date 2021/11/10
     **/
    public static String fixBits(String num, int bit, int fromBaseSystem, int toBaseSystem) {
        int integer = Integer.valueOf(num, fromBaseSystem);
        integer = 1 << bit | integer;
        String toNum = "";
        switch (toBaseSystem) {
            case 16:
                toNum = Integer.toHexString(integer);
                break;
            case 10:
                toNum = Integer.toString(integer);
                break;
            case 8:
                toNum = Integer.toOctalString(integer);
                break;
            case 2:
                toNum = Integer.toBinaryString(integer);
                break;
            default:
                break;
        }
        return toNum.substring(1);
    }

    //    private static Map<String, Integer> decode(String identifierValue){
//        Map<String, Integer> map = new HashMap<>(2);
//        int value = Integer.parseInt(identifierValue, 16);
////        取出低字节，
//        int lowByte = value & 0xff;
////        取出低字节的低3位，小数点个数
//        int lowThreeBit = lowByte & 0x07;
////        取出低字节的高5位，数据字节数
//        int highfiveBit = (lowByte & 0xf8) >> 3;
//        map.put("lowThreeBit", lowThreeBit);
//        map.put("highfiveBit", highfiveBit);
//        return map;
//    }
}
